using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Xml.Serialization;
using GraphAlgsPresentation.Core;
using System.ComponentModel;

namespace GraphAlgsPresentation.ScriptLibrary
{
    /// <summary>
    /// Provides a change edge label color command
    /// </summary>
    [Serializable]
    public class ChangeEdgeLabelColor : Command
    {
        private string srcName;

        /// <summary>
        /// returns source vertex's name
        /// </summary>
        public string SourceName
        {   
            get { return srcName; }
            set { srcName = value; }
        }

        private string dstName;

        /// <summary>
        /// returns destination vertex's name
        /// </summary>
        public string DestinationName
        {
            get { return dstName; }
            set { dstName = value; }
        }

        private Color newColor;

        /// <summary>
        /// returns new edge's label color
        /// </summary>
        [XmlIgnore]
        public Color NewColor
        {
            get { return newColor; }
            set { newColor = value; }
        }

        /// <summary>
        /// Gets or sets the new color of the XML.
        /// </summary>
        /// <value>The new color of the XML.</value>
        [Browsable(false)]
        public string XMLNewColor
        {
            get { return XmlDataConverter.SerializeColor(this.NewColor); }
            set { this.NewColor = XmlDataConverter.DeserializeColor(value); }
        }

        private Color oldColor;
        /// <summary>
        /// Gets or sets the old color.
        /// </summary>
        /// <value>The old color.</value>
        [XmlIgnore]
        [Browsable(false)]
        public Color OldColor
        {
            get { return oldColor; }
            set { oldColor = value; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeEdgeLabelColor"/> class.
        /// </summary>
        /// <param name="v1">Source vertex's name</param>
        /// <param name="v2">Destination vertex's name</param>
        /// <param name="color">New edge's label color</param>
        /// <param name="effect">A DrawEffect enum. Default is DrawEffect.NoEffect</param>
        public ChangeEdgeLabelColor(string v1, string v2, Color color, DrawEffect effect)
        {
            srcName = v1;
            dstName = v2;
            newColor = color;
            Effect = effect;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeEdgeLabelColor"/> class.
        /// </summary>
        /// <param name="v1">Source vertex's id</param>
        /// <param name="v2">Destination vertex's id</param>
        /// <param name="color">New edge's label color</param>
        /// <param name="effect">A DrawEffect enum. Default is DrawEffect.NoEffect</param>
        public ChangeEdgeLabelColor(int v1, int v2, Color color, DrawEffect effect)
        {
            srcName = (v1 + 1).ToString();
            dstName = (v2 + 1).ToString();
            newColor = color;
            Effect = effect;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeEdgeLabelColor"/> class.
        /// </summary>
        public ChangeEdgeLabelColor()
        {
        }

        /// <summary>
        /// Runs this instance.
        /// </summary>
        public override void Run()
        {
            LCEdge e = this.Context.GetEdge(srcName, dstName);
            oldColor = e.LabelColor;
            e.LabelColor = newColor;
            e.Updated = true;
            //this.Context.Layout.ReDraw();
        }

        /// <summary>
        /// Undoes this instance.
        /// </summary>
        public override void Undo()
        {
            LCEdge e = this.Context.GetEdge(srcName, dstName);
            e.LabelColor = OldColor;
            e.Updated = true;
        }
    }
}
